package com.fangqiang.sprint_boot_web1.validate.controller;

import com.fangqiang.sprint_boot_web1.validate.data.Person;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

// controller层中，该注解可以不加（默认有）
@Validated
@Controller
public class ValidateController {

    @PostMapping("/test")
    public String test(@Valid @RequestBody Person person, BindingResult result){
        System.out.println(person);
        System.out.println(result);
        return "ok";
    }

    @PostMapping("/test2")
    public String test1(@Valid @RequestBody Person person){
        System.out.println(person);
        return "ok";
    }
}
